package 深入反射机制.反射属性Field.获取属性各种信息.test01;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

//反射Student类当中所有的Field
public class ReflectTest01 {
    public static void main(String[] args) {
        Class studentClass = Student.class;
        String className = studentClass.getName();
        System.out.println("完整类名："+ className);

        String simpleName = studentClass.getSimpleName();
        System.out.println("简单类名：" + simpleName);

        //获取所有的public的Field
        Field[] fields = studentClass.getFields();

        System.out.println(fields.length);
        Field f = fields[0];
        String fieldName = f.getName();
        System.out.println(fieldName);

        //获取所有的Field
        Field[] fieldAll = studentClass.getDeclaredFields();

        System.out.println(fieldAll.length + "\n" + "============================");

        for (Field field :fieldAll ){

            //获取属性修饰符列表
            int i = field.getModifiers();
            String modifierName = Modifier.toString(i);

            //获取属性类型
            String classTypeName = field.getType().getSimpleName();
            System.out.println(field.getName()+ "\t" + "属性修饰符：" + modifierName + "\t" + "属性类型：" + classTypeName);
        }
    }
}
